package fr.umlv.jee.jawp.service.configuration;

import java.util.LinkedList;
import java.util.List;

import org.jawp.persistence.Product;
import org.jawp.persistence.ProductDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import com.mongodb.BasicDBObject;
import com.mongodb.DBCursor;
import com.mongodb.DBObject;

public class ProductService {
	@Autowired
	private ProductDAO dao;

	/*************************************
	 *				Creation
	 *************************************/

	@Transactional
	public Product createNewProduct(String name, int categoryId) { //TODO check if category exists ?
		return dao.createNewProduct(name, categoryId);
	}

	/*************************************
	 *				Getter
	 *************************************/

	@Transactional(readOnly = true)
	public List<Product> getProducts() {		 
		return dao.getProducts();
	}

	@Transactional(readOnly = true)
	public List<Product> getProductsByCategory(int categoryId) {		 
		return dao.getProductsByCategory(categoryId);
	}

	@Transactional(readOnly = true)
	public Product getProductById(int id) {		 
		return dao.getProductById(id);
	}

	@Transactional(readOnly = true)
	public Product getProductByNameAndCategory(String name, int categoryId) {		 
		return dao.getProductByNameAndCategory(name, categoryId);
	}

	/*************************************
	 *				Setter
	 *************************************/

	/*************************************
	 *				Deletion
	 *************************************/

	@Transactional
	public void deleteProduct(int id) {
		dao.deleteProduct(id);
	}

	@Transactional
	public void deleteProductsByCategory(int categoryId) {
		dao.deleteProductsByCategory(categoryId);
	}
}
